package com.hexacta.hrs.sandbox.meetings.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.hexacta.hrs.sandbox.meetings.data.MentorDao;
import com.hexacta.hrs.sandbox.meetings.model.Mentor;
import com.hexacta.hrs.sandbox.meetings.service.MentorsService;

/**
 * Administra los Mentores.
 * @author ncortinez
 */

@Transactional
public class MentorsServiceImpl implements MentorsService {
	
	private MentorDao mentorDAO;
	
	public MentorsServiceImpl() {
		this.setMentorDAO(new MentorDao());
	}

	public Mentor create(String name) {
		Mentor mentor = new Mentor();
		mentor.setName(name);
		return mentor;
	}

	public void update(Object o) {
		this.getMentorDAO().saveOrUpdate(o);
		return;
	}

	public Mentor findById(long i) {
		Mentor mentor = this.getMentorDAO().findById(i);
		return mentor; 
	}
	
	public Mentor findByName(String name){
		List<Mentor> mentors = this.getMentorDAO().findByName(name);
		if(mentors.iterator().hasNext()){
			return mentors.iterator().next();
		}
		return null;
	}
	
	public Boolean mentorExists(String name) {
		return (this.findByName(name) != null);
	}
	
	public void save(Mentor mentor) {
		this.getMentorDAO().saveOrUpdate(mentor);
		return;
	}
	
	public void delete(Mentor mentor){
		this.getMentorDAO().delete(mentor);
	}

	public List<Mentor> select() {
		List<Mentor> mentors = this.getMentorDAO().findAll();
		return mentors; 
	}
	
	public MentorDao getMentorDAO() {
		return mentorDAO;
	}

	public void setMentorDAO(MentorDao userDAO) {
		this.mentorDAO = userDAO;
	}

}